perf: Jobify SendBatchedMessages in UnityTransport [MTT-4999]#2304
Merged
simon-lemay-unity merged 2 commits intodevelopfrom Nov 10, 2022
Merged
perf: Jobify SendBatchedMessages in UnityTransport [MTT-4999]#2304simon-lemay-unity merged 2 commits intodevelopfrom
simon-lemay-unity merged 2 commits intodevelopfrom
Conversation
dbuckley3d
approved these changes
Nov 10, 2022
jakobbbb
pushed a commit
to GooseGirlGames/com.unity.netcode.gameobjects
that referenced
this pull request
Feb 22, 2023
…Technologies#2304) * Make ErrorUtilities usable from Burst * Jobify SendBatchedMessages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR jobifies the
SendBatchedMessagesmethod inUnityTransport. The main goal of this operation is just to move theBeginSendandEndSendcalls into Burst-compiled code, since otherwise they end up generating GC allocations when invoking their Burst function pointers.To demonstrate that this results in a performance gain, I profiled a simple Boss Room play session. Here's a representative frame without the changes:
And here's a similar frame with the changes applied:
As can be observed, GC allocations are completely gone from
SendBatchedMessagesand its runtime is also reduced.There's still much more that we could do to take advantage of jobs here. For example, we could parallelize the sends for all the targets (although we should profile that; the cost of scheduling these jobs may be more than the savings we'd get). But for now I went with the simplest change that moved us forward.
This PR also modifies the
ErrorUtilitiesto be usable from within Burst. While modifying that, I also removed support for a bunch of error codes that simply can't be returned here (either because our APIs don't return them anymore, or because the usage patterns inUnityTransportmake them impossible to encounter).Changelog
N/A (Didn't think it worthy of a changelog entry. Let me know if you feel otherwise.)
Testing and Documentation